<template>
  <div>
    <home-header></home-header>
    <home-swiper :list="swiperList"></home-swiper>
    <home-recommend :list="recommendList"></home-recommend>
    <!-- <home-weekend :list="weekendList"></home-weekend> -->
  </div>
</template>

<script>
/* eslint-disable */
import HomeHeader from "./components/Header.vue";
import HomeSwiper from "./components/Swiper.vue";
// import HomeWeekend from "./components/Weekend.vue";
import HomeRecommend from "./components/Recommend.vue";
import axios from "axios";

/* eslint-disable */
export default {
  name: "Home",
  components: {
    HomeHeader,
    HomeSwiper,
    HomeRecommend,
  },
  data() {
    return {
      swiperList: [],
      recommendList: [],
      weekendList: [],
      lastCity: "",
    };
  },
  methods: {
    getHomeInfo() {
      console.log("从数据库中获取数据");
      axios.defaults.baseURL = process.env.BASE_API;
      console.log(process.env.BASE_API);
      axios.get("/api/home/list").then(this.getHomeInfoSucc);
    },
    getHomeInfoSucc(res) {
      console.log(res);
      res = res.data;
      if (res.ret && res.data) {
        this.swiperList = res.data.swiperList;
        this.iconList = res.data.iconList;
        this.recommendList = res.data.recommendList;
        this.weekendList = res.data.weekendList;
      }
    },
  },
  mounted() {
    this.lastCity = this.$store.state.city;
    this.getHomeInfo();
  },
  activated() {
    if (this.lastCity !== this.$store.state.city) {
      this.lastCity = this.$store.state.city;
      //   this.getHomeInfo();
    }
    this.getHomeInfo();
  },
};
</script>

<style scoped>
</style>
